/**
 * 
 * @param {*} type get/post
 * @param {*} url 服务器地址
 * @param {*} isAsyn 是否异步
 * @param {*} data 请求参数
 * @param {*} callBack 回调函数
 */
function ajaxFun(type, url, isAsyn, data, callBack) {
 
    //1.创建对象
    let xhr = new XMLHttpRequest();
     type = type.toLowerCase();

    if (type == "get") {
        let urlParams = url;
        if (data != "") {
            //"6.ajaxFun?name=laowang&pwd=666"
            urlParams += "?" + data;
        }
        //2.
        xhr.open(type, urlParams, isAsyn);
        //3.
        xhr.send();
    } else if (type == "post") {
        xhr.open(type, url, isAsyn);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(data);
    } else {
        console.log("类型错误");
    }

    //4.状态码事件
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            //5.
            callBack(xhr.responseText);
        }
    }
}